# -*- coding: utf-8 -*-
"""
Created on Mon Sep 10 18:52:24 2012

@author: xudi
"""

import numpy as np
import pylab as pl

'''index'''
lam=7.8e-7
C=3e8
dz=lam/1000
dt=dz/(2*C)
aa=0
sampling_rate = 1/dt
fft_size = 50000
tw=5e-16# use to change the frequence
t0=2e-15
t = np.arange(0.,1e-14,dt)

'''gaussian pluse and fft '''
ft=np.exp(-(t-t0)**2/tw**2)
x=ft[:fft_size]
xf1=np.fft.fft(x,fft_size)
xf2=np.abs(np.fft.fftshift(xf1))
freqs=np.linspace(0,sampling_rate,fft_size)-sampling_rate/2


'''for test the 3db size''' 
n=0
for n in range(0,fft_size):
    if xf2[n]==xf2.max() :
        aa=n
        for n in range(aa,fft_size):
            bb=0
            if xf2[n] < xf2.max()*((2**0.5)/2):
                bb=n
                break
            n+=1
    n+=1
    
wc=4*np.pi*freqs[bb]
print tw
print fft_size
print'%e'%wc

pl.figure(figsize=(8,6))
pl.subplot(211)
pl.plot(t[:fft_size],x)
pl.subplot(212)
pl.xlim(-1e16,1e16)
pl.plot(freqs,xf2)
pl.show()



''' size=10000 tw=5e-16  sample_rate= 1/dt   w3db=4.78e15'''
